package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.ClassBean;

import com.project.mapper.IClassMapper;
import com.project.mapper.IStudentMapper;
import com.project.service.IClassService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ClassServiceImpl implements IClassService {
    @Autowired
    private IClassMapper classMapper ;
    @Autowired
    private IStudentMapper studentMapper ;
    @Override
    public List<ClassBean> findAll() {
        return classMapper.selectList(null);
    }

    @Override
    public boolean del(Integer id) {
        QueryWrapper<ClassBean> qw = new QueryWrapper<>();

        if (studentMapper.countByClass(id)==0){
            classMapper.deleteById(id);
            return true;
        }else {
            return false;
        }
    }

    @Override
    public void add(ClassBean classBean) {
       classMapper.insert(classBean);
    }
}
